$(function () {
    $.ajax({
        url: 'http://127.0.0.1:3000/api/getindexmenu',
        dataType: 'JSON',
        success: function (data) {
            console.log(data);
            // var datas = eval("("+data+")");
            var datas = JSON.parse(data);
            datas = datas.result;
            console.log(datas);
            var li = '';

            var len = datas.length;
            for (var i = 0; i < len; i++) {
                li += '<li><a href=' + datas[i].titlehref + '>' +
                    datas[i].img +
                    '<span>' + datas[i].name + '</span></a></li>';
            }
            li = $(li);
            console.dir(li);
            $('#noom').append(li);
            //点击更多,显示隐藏最后四个
            li.eq(7).on('click', function () {
                console.log($(".menu_list li:nth-last-child(-n+4)"));
                $(".menu_list li:nth-last-child(-n+4)").toggle();
            });
        }
    });
    //商品分类展示
    $.getJSON('http://127.0.0.1:3000/api/getmoneyctrl', function (data) {
        console.log(data);
        var datas = data.result;
        var len = datas.length;
        console.log(datas);
        var str = '';
        var arr = [];
        for (var i = 0; i < len; i++) {
            var comm = datas[i].productComCount;
            comm = comm.replace('有', '');
            comm = comm.replace('人评论', '');
            arr.push(comm);
            console.log(arr);
            str += '<li>' +
                '<div class="product_img f_left">' +
                '</div>' +
                '<div class="product_info f_left">' +
                '<p class="product_title">' +
                '<span class="pTitle">' + datas[i].productName + '</span>' +
                '<span class="price">' + datas[i].productPinkage + '</span>' +
                '</p>' +
                '<p class="product_otherinfo">' +
                '<span class="productFrom">' + datas[i].productFrom + '</span>&nbsp;|&nbsp;' + '<span class="productTime">' + datas[i].productTime + '</span>' +
                '<span class="commit">' + arr[i] + '</span>  ' +
                '<img src="./images/discuss.png">' + 
                '</p>' +
                '</div>' +
                '</li>';
        }
        $('.discount ul').html(str);

    });
    $('.toSavemoeny').attr('href', './web/savamoney.html?pageid=0');
});